/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.software;

import com.mapping.Software;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author PARDmx
 */
@Namespace(value = "/")
@Action(value = "gestionSoftwareP", results = {
    @Result(name = "success", location = "/GestionSoftware/gestionSoftware.jsp")})
public class GestionSoftware extends ActionSupport{
    private List<Software> softwares;
    
    @Override
    public String execute() throws Exception {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();  
        softwares = (List<Software>)em.createNamedQuery("Software.findAll").getResultList();
        em.flush();
        tx.commit();
        em.close();
        return SUCCESS;
    } 

    public List<Software> getSoftwares() {
        return softwares;
    }
        
}
